<template>
  <div class="storeInventory">
    <!-- 库存与调货 -->
    <div class="cog-top">
      <div>
        <p style="margin-left: 15px">款号</p>
        <el-input v-model="kindsNumber"></el-input>
        <p>品牌</p>
        <el-select class="top-inp" v-model="brandName">
          <el-option
            v-for="item in brandList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
        <p>客户</p>
        <el-input
          v-model="searchNo"
          style="width: 60px; margin-right: 10px"
          @blur="searchNoBlur"
        ></el-input>
        <el-select v-model="searchName" @change="searchNameChange">
          <el-option
            v-for="item in shopList"
            :key="item.value + Math.random()"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
        <p>季度</p>
        <el-select v-model="quarterIdList" multiple collapse-tags>
          <el-option
            v-for="item in quarterList1"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
        <p>调入店铺</p>
        <el-input
          v-model="customerNo"
          style="width: 60px; margin-right: 10px"
          @blur="change1"
        ></el-input>
        <el-select v-model="customerName" @change="change2">
          <el-option
            v-for="item in shopList"
            :key="item.value + Math.random()"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
        <p>调出店铺</p>
        <el-input
          v-model="callout"
          style="width: 60px; margin-right: 10px"
          @blur="change3"
        ></el-input>
        <el-select v-model="calloutName" @change="change4">
          <el-option
            v-for="item in shopList"
            :key="item.value + Math.random()"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </div>
      <div class="riqi">
        <p>操作员</p>
        <el-input v-model="operator" disabled></el-input>
        <p>客存</p>
        <el-input v-model="repertoryValue" style="width: 160px">
          <template slot="prepend">>=</template></el-input
        >
        <p>备注快递</p>
        <el-input v-model="courier" style="width: 230px"></el-input>
        <p>调货日期</p>
        <el-date-picker
          unlink-panels
          v-model="dateList"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd HH:mm:ss"
        ></el-date-picker>
      </div>
    </div>
    <div class="cog-btn">
      <div>
        <el-button @click="search" icon="el-icon-search" type="primary"
          >查询</el-button
        >
        <el-button @click="exportBtnClick" icon="el-icon-upload2"
          >导出</el-button
        >
        <el-button v-print="'#outTable'" icon="el-icon-printer"
          >预调列印</el-button
        >
        <el-button @click="generate" icon="el-icon-printer"
          >生成客进退单</el-button
        >
        <el-checkbox
          v-model="showImg"
          label="显示图片"
          border
          style="margin-left: 10px"
        ></el-checkbox>
      </div>
    </div>
    <div class="cog-tab">
      <div id="content1">
        <div>
          <p>店铺库存表</p>
        </div>
        <el-table
          id="outTable"
          ref="table2"
          :summary-method="getList"
          show-summary
          :cell-class-name="tableCellClassName"
          @cell-click="cellClick"
          @row-dblclick="dbClick"
          border
          :header-cell-style="{
            background: '#f4f4f4',
            padding: 0,
            height: '40px'
          }"
          :cell-style="{ padding: 0, height: '25px' }"
          highlight-current-row
          :data="tableData2"
          style="width: 100%; margin-top: 10px"
          height="61vh"
          @row-click="rowClick1"
        >
          <template v-for="i in knhList">
            <el-table-column
              show-overflow-tooltip
              :prop="i.prop"
              :label="i.label"
              :width="i.width"
              :key="i.prop"
            ></el-table-column>
          </template>
        </el-table>
        <!-- 分頁 -->
        <!-- :pager-count="5" 设置显示最大页码数 超过用 … 显示 -->
        <el-pagination
          small
          background
          :pager-count="Count"
          layout="prev, pager, next, jumper, sizes"
          :page-sizes="[20, 50, 100, 200]"
          :page-size="limit"
          :page-count="pagesNum"
          :total="dataLen"
          @current-change="handleCurrentChange"
          @size-change="handleSizeChange"
        ></el-pagination>
        <foot-view class="footView">
          <div slot="text">
            <span>数据库：{{ jxQuarter }}</span>
          </div>
        </foot-view>
      </div>
      <div class="divider" @click="dividerClick">
        <i v-if="areaFlag" class="el-icon-arrow-right"></i>
        <i v-if="!areaFlag" class="el-icon-arrow-left"></i>
      </div>
      <div id="content2">
        <div>
          <p>店铺调货表</p>
          <el-select v-model="sequenceStatus" style="float: right">
            <el-option
              v-for="item in commodityTypeList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </div>
        <el-table
          ref="table1"
          border
          :cell-class-name="tableCellClassName"
          @cell-click="cellClick1"
          :header-cell-style="{
            background: '#f4f4f4',
            padding: 0,
            height: '40px'
          }"
          :cell-style="{ padding: 0, height: '25px' }"
          highlight-current-row
          @row-click="rowClick"
          :data="tableData1"
          style="width: 100%; margin-top: 10px"
          height="61vh"
        >
          <el-table-column
            show-overflow-tooltip
            prop="transferCargoSequence"
            label="客户调货序号"
            width="140px"
          ></el-table-column>
          <el-table-column
            show-overflow-tooltip
            prop="calloutCustomerName"
            label="调出店铺"
            width="130px"
          ></el-table-column>
          <el-table-column
            show-overflow-tooltip
            prop="foldCustomerName"
            label="调入店铺"
            width="130px"
          ></el-table-column>
          <el-table-column
            show-overflow-tooltip
            prop="kindsNumber"
            label="货号"
            width="130"
          ></el-table-column>
          <el-table-column
            show-overflow-tooltip
            prop="sellingPrice"
            label="售价"
          ></el-table-column>
          <el-table-column
            show-overflow-tooltip
            prop="number"
            label="数量"
          ></el-table-column>
          <el-table-column
            show-overflow-tooltip
            prop="transferCargoTime"
            label="调货日期"
            width="160"
          ></el-table-column>
          <el-table-column
            show-overflow-tooltip
            prop="inputSequence"
            label="进货序号"
            width="140"
          ></el-table-column>
          <el-table-column
            show-overflow-tooltip
            prop="outSequence"
            label="退货序号"
            width="120"
          ></el-table-column>
          <el-table-column
            show-overflow-tooltip
            prop="sequenceStatus"
            label="调货状态"
          ></el-table-column>
        </el-table>
        <el-pagination
          small
          background
          :pager-count="Count1"
          layout="prev, pager, next, jumper, sizes"
          :page-sizes="[20, 50, 100, 200]"
          :page-size="limit1"
          :page-count="pagesNum1"
          :total="dataLen1"
          @current-change="handleCurrentChange1"
          @size-change="handleSizeChange1"
        ></el-pagination>
      </div>
    </div>
    <foot-view class="footView">
      <div slot="text">
        <span>数据库：{{ jxQuarter }}</span>
        <span>操作员：{{ operator }}</span>
        <span>记录数：{{ amount }}</span>
      </div>
    </foot-view>

    <show-image
      v-if="showImg"
      :imgSrc="imgSrc"
      @closeImg="
        () => {
          this.showImg = false
        }
      "
    ></show-image>
  </div>
</template>

<script>
//
// 配合后端导出的方法
import {
  exportExcel,
  isBoolean_isExport_excel
} from '../../../util/exportExcel.js'

import footView from '../../../components/FootView'
import {
  getStoreInventory,
  getTransfer,
  getSerial
} from '../../../network/vipClient'
import { getBranded } from '../../../network/branded'
import { getQuarter } from '../../../network/quarter'
import { getClient } from '../../../network/client'
import today from '../../../components/mixins/today'
import outex from '../../../components/mixins/outexp'
import {
  addCustomerInputOutSingle,
  insert
} from '../../../network/customerTransfer'
import { getKindsNumberList } from '../../../network/artNo'
import { getBarCode } from '../../../network/manufacturer'

import cookieFn from '../../../components/mixins/cookieFn'

import showImage from '../../../components/showImage.vue'

export default {
  name: 'store_query_transfer',
  mixins: [today, outex, cookieFn],
  components: {
    footView,
    showImage
  },
  data() {
    return {
      showImg: false,
      imgSrc: '',
      areaFlag: false,
      customerId: '',
      searchNo: '',
      searchName: '',

      Count: 5, //页码设置显示最大页码数 超过用 … 显示
      limit: 20, //本页条数
      pagesNum: 0, //当前页
      dataLen: 0, //总数据条数
      currentPage: 1, // 当前页码

      Count1: 5, //页码设置显示最大页码数 超过用 … 显示
      limit1: 20, //本页条数
      pagesNum1: 0, //当前页
      dataLen1: 0, //总数据条数
      currentPage1: 1, // 当前页码
      jxQuarter:null,
      operator:null,
      // jxQuarter: document.cookie.match(
      //   new RegExp('jxQuarter' + name + '=([^;]*)(;|$)')
      // )[1],
      jxStore: this.getCookie('jxStore') == '1',
      // operator: document.cookie.match(RegExp('jxUser' + '=([^;]+)'))[1],
      repertoryValue: '',
      customerNo: '',
      customerName: '',
      quarterIdList: '',
      quarterList1: [],
      brandName: '',
      callout: '',
      calloutName: '',
      kindsNumber: '',
      brandName: '',
      shopList: [],
      ary1: ['客户id', '首进日'],

      dateList: '',
      courier: '',
      brandList: [],

      // twoDimensional:false,
      sequenceStatus: '',
      commodityTypeList: [
        { value: '全部', label: '全部' },
        { value: '预调', label: '预调' },
        { value: '已调', label: '已调' }
      ],

      tableData1: [], // 右边表格数据
      tableData2: [], // 左边表格数据

      knhList: [
        // 下面注释是原来的
        // { prop: 'customerNo', label: '客户编号', width: '' },
        // { prop: 'customerName', label: '客户简称', width: '' },
        // { prop: 'styleNumber', label: '型号', width: '110' },
        // { prop: 'colorNo', label: '色号', width: '55' },
        // { prop: 'colorName', label: '颜色', width: '55' },
        // { prop: 'repertoryFiveNumber', label: '05-XS', width: '50' },
        // { prop: 'repertorySevenNumber', label: '07-S', width: '50' },
        // { prop: 'repertoryNineNumber', label: '09-M', width: '50' },
        // { prop: 'repertoryElevenNumber', label: '11-L', width: '50' },
        // { prop: 'repertoryThirteenNumber', label: '13-XL', width: '50' },
        // { prop: 'repertoryFifteenNumber', label: '15-2XL', width: '50' },
        // { prop: 'repertorySeventeenNumber', label: '17-3XL', width: '50' },
        // { prop: 'repertoryNineteenNumber', label: '19-4XL', width: '50' },
        // { prop: 'repertoryTwentyOneNumber', label: '21-5XL', width: '50' },
        // { prop: 'repertoryTwentyThreeNumber', label: '23-6XL', width: '50' },
        { prop: 'no', label: '客户编号', width: '120' },
        { prop: 'customerName', label: '客户简称', width: '120' },
        { prop: 'typeNumber', label: '型号', width: '120' },
        { prop: 'colorNo', label: '色号', width: '120' },
        { prop: 'colorName', label: '颜色', width: '120' },
        { prop: 'c05', label: '05-XS', width: '80' },
        { prop: 'c07', label: '07-S', width: '80' },
        { prop: 'c09', label: '09-M', width: '80' },
        { prop: 'c11', label: '11-L', width: '80' },
        { prop: 'c13', label: '13-XL', width: '80' },
        { prop: 'c15', label: '15-2XL', width: '80' },
        { prop: 'c17', label: '17-3XL', width: '80' },
        { prop: 'c19', label: '19-4XL', width: '80' },
        { prop: 'c21', label: '21-5XL', width: '80' },
        { prop: 'c23', label: '23-6XL', width: '80' },
        { prop: 'f', label: 'F', width: '80' },
        { prop: 'totalSizeNum', label: '小计', width: '80' },
        { prop: 'brandedName', label: '品牌名称', width: '140' }
      ],
      amount: 0,
      detailData: '',
      showData: '',
      details: '',
      label: '',
      label1: '',
      saveList: [],
      manufacturerBarCode: []
    }
  },
  methods: {
    dividerClick() {
      let content1 = document.getElementById('content1')
      let content2 = document.getElementById('content2')
      if (this.areaFlag) {
        content2.style.width = '30%'
        content1.style.width = '69%'
      } else {
        content2.style.width = '60%'
        content1.style.width = '39%'
      }
      this.areaFlag = !this.areaFlag
    },
    // 点击导出的时候，触发的函数
    async exportBtnClick() {
      // 先判断后端给的接口，如果返回的是111500,证明导不了，直接return，否则直接导出
      const { data: res } = await isBoolean_isExport_excel()
      console.log(res, 'isBoolean_isExport_excel')
      if (res.code === 111500) return // 不用提示了，在响应拦截器已经提示
      // 通过之后，可以导出 这个对象查询的那个对象是一样的，只是开启了导出
      const exportObj = {
        totalStock: false, // 总存开关,false代表关闭总存，true证明要总存
        actualAmount: '', // 实进量
        actualSell: '', // 实销量
        brandedNameList: this.brandName || [], // 品牌名称数组
        businessList: [], // 业务数组
        commodityNameList: [], // 品名名称数组
        commodityTypeList: [], // 大类（部类编号）数组
        customerNoList: this.searchNo || [], // 客户编号数组 (客户)
        customerRepertory: this.repertoryValue || '', // 客存 >=
        endDate: '', // 结束日期(yyyy-MM-dd HH:mm:ss)
        factoryRepertory: '', // 库存 >=
        headquartersNo: '', // 总店编号
        isExport: true, // 是否导出
        isCustomerTotal: 0, // 客户合计 0未开启1开启
        isHeadquartersTotal: 0, // 总店合计 0未开启1开启
        isRepertoryZero: '', // 累计 <> 0 (库存>0) 0未开启1开启
        kindsNumberList: [], //  货号数组（款号）
        limit: this.limit, // 分页条数
        page: this.currentPage, // 当前的页码
        quartIdList:
          JSON.stringify(this.quarterIdList)
            .replace(/\[|]/g, '')
            .replace(/\"|"/g, '') || [], // 季度id数组
        // 如果多选下拉框是一个数组，那么就要转字符串取数组
        quartNameList: [], // 季度名称数组
        selectType: 2, // 查询类型 1：一维表 2：二维表
        softwareCustomerId: '', // 软件客户id
        startDate: '', // 开始日期(yyyy-MM-dd HH:mm:ss)
        styleNumberList: this.kindsNumber || [], //型号(款号)数组，多个款号用 ','分割
        type: 0, // 身份（0客户1厂商）
        warehouseNo: '' // 仓库编号
      }
      exportExcel(exportObj, '二维表格.xlsx')
    },
    // 下面是原来的导出
    Exp() {
      let obj = {
        styleNumberList: this.kindsNumber,
        inventory: this.repertoryValue,
        isHeadquarters: false,
        isExport: true,
        'pageData.page': this.currentPage,
        'pageData.limit': this.limit,
        isCustomerTotal: false,
        inventoryExpression: -1,
        noExportList: JSON.stringify(this.ary1)
          .replace(/\[|]/g, '')
          .replace(/\"|"/g, '')
      }
      getStoreInventory(obj).then((res) => {
        console.log(res.data)
        if (res.data.data != null) {
          location.href = `${res.data.data}`
        }
      })
    },
    handleSizeChange1(val) {
      //每页多少条
      this.limit1 = val
      this.pagesNum1 = Math.ceil(this.dataLen1 / this.limit1)
      this.search()
    },
    handleCurrentChange1(val) {
      //当前页
      this.currentPage1 = val
      this.search()
    },
    handleSizeChange(val) {
      //每页多少条
      this.limit = val
      this.pagesNum = Math.ceil(this.dataLen / this.limit)
      this.search()
    },
    handleCurrentChange(val) {
      //当前页
      this.currentPage = val
      this.search()
    },
    rowClick1(row) {
      // console.log(row, 'row')
      // 没有点击显示图片的话，直接return
      if (!this.showImg) return
      if (row.image) {
        this.imgSrc = row.image
      } else {
        this.imgSrc = ''
        this.$message.info('暂无图片')
      }
    },
    rowClick(e) {
      this.details = e
    },
    //生成客进退单
    generate() {
      if (this.saveList == '') {
        this.$message({
          type: 'warning',
          offset: 400,
          message: '请选中右表数据 生成客进退单'
        })
        return
      }
      addCustomerInputOutSingle(JSON.stringify(this.saveList)).then((res) => {
        console.log(res.data)
        if (res.data.code == 200) {
          this.$message({
            type: 'success',
            message: '生成进退单成功'
          })
        }
      })
    },
    tableCellClassName({ row, column, rowIndex, columnIndex }) {
      //注意这里是解构
      //利用单元格的 className 的回调方法，给行列索引赋值
      row.index = rowIndex
      column.index = columnIndex
    },
    cellClick(row, column, cell, event) {
      // console.log(row.index);//点击第几行 从0开始
      // console.log(column.index);//点击第几列
      // console.log(column.label.split('-'))//点击某一列的label
      // console.log(row[column.property])//点击第几行第几列的值
      this.label = column.label.split('-')
      this.label1 = this.label[this.label.length - 1] //数组最后一个元素
      this.detailData = row[column.property]
    },
    cellClick1(row, column) {
      console.log(row.transferCargoSequence) //点击获取 此行中的序号
      getSerial({
        transferCargoSequence: row.transferCargoSequence,
        sequenceStatus: '预调'
      }).then((res) => {
        console.log(res.data)
        if (res.data.code == 200) {
          this.saveList = res.data.data.customerTransferCargoInfoList
          console.log(this.saveList)
        }
      })
    },
    dbClick(e) {
      let knList = []
      if (this.manufacturerBarCode.styleColorSize) {
        // 型尺色

        if (this.manufacturerBarCode.styleColor) {
          // 款号与尺码之间有 -

          if (this.manufacturerBarCode.colorSize) {
            // 色号与尺码之间有 -
            knList.push({
              kindsNumber: `${e.typeNumber}-${this.label1}-${e.colorNo}`
              // number:e[f]
            })
          } else {
            // 色号与尺码之间没有 -
            knList.push({
              kindsNumber: `${e.typeNumber}-${this.label1}${e.colorNo}`
              // number:e[f]
            })
          }
        } else {
          // 款号与尺码之间没有 -

          if (this.manufacturerBarCode.colorSize) {
            // 色号与尺码之间有 -
            knList.push({
              kindsNumber: `${e.typeNumber}${this.label1}-${e.colorNo}`
              // number:e[f]
            })
          } else {
            // 色号与尺码之间没有 -
            knList.push({
              kindsNumber: `${e.typeNumber}${this.label1}${e.colorNo}`
              // number:e[f]
            })
          }
        }
      } else {
        // 型色尺

        if (this.manufacturerBarCode.styleColor) {
          // 款号与颜色之间有 -

          if (this.manufacturerBarCode.colorSize) {
            // 色号与尺码之间有 -
            knList.push({
              kindsNumber: `${e.typeNumber}-${e.colorNo}-${this.label1}`
              // number:e[f]
            })
          } else {
            // 色号与尺码之间没有 -
            knList.push({
              kindsNumber: `${e.typeNumber}-${e.colorNo}${this.label1}`
              // number:e[f]
            })
          }
        } else {
          // 款号与颜色之间没有 -

          if (this.manufacturerBarCode.colorSize) {
            // 色号与尺码之间有 -
            knList.push({
              kindsNumber: `${e.typeNumber}${e.colorNo}-${this.label1}`
              // number:e[f]
            })
          } else {
            // 色号与尺码之间没有 -
            knList.push({
              kindsNumber: `${e.typeNumber}${e.colorNo}${this.label1}`
              // number:e[f]
            })
          }
        }
      }
      console.log(knList)
      return
      if (this.callout == '') {
        this.$message({
          type: 'warning',
          offset: 400,
          message: '调出店铺编号不能为空'
        })
        return
      }
      console.log(e)
      // this.showData = `${e.typeNumber}-${e.colorNo}-${this.detailData}`
      this.showData = `${e.typeNumber}-${e.colorNo}`
      console.log(e.no)
      console.log(this.showData)
      let obj = {
        callout: this.callout,
        repertoryValue: this.repertoryValue,
        calloutName: this.calloutName,
        fold: this.customerNo,
        foldName: this.customerName,
        kindsNumber: 'AAA-AAAS05',
        // kindsNumber:`${e.typeNumber}-${e.colorNo}${this.label1}`,
        number: 1,
        operator: document.cookie.match(RegExp('jxUser' + '=([^;]+)'))[1],
        cooperateWay: '配货'
      }
      console.log(JSON.stringify([obj]))
      insert(JSON.stringify([obj])).then((res) => {
        console.log(res.data)
        if (res.data.code == 200) {
          this.$message({
            type: 'warning',
            offset: 400,
            message: '调转成功'
          })
        }
      })
    },
    /*
        点击查询的时候，触发的函数
    */

    async search() {
      // const { data: res } = await getAllInventoryDataApi()
      // console.log(res, ' getAllInventoryDataApi()')
      // 这个obj是原来的
      // let obj = {
      //   styleNumberList: this.kindsNumber, // 型号就是款号
      //   inventory: this.repertoryValue, // 客存的值
      //   isHeadquarters: false,
      //   isExport: false, // 是否开启导出
      //   'pageData.page': this.currentPage,
      //   'pageData.limit': this.limit,
      //   isCustomerTotal: false,
      //   inventoryExpression: -1,
      //   customerId: this.customerId
      // }
      // 后端要求这个对象，即使没有值也是要传的
      const obj = {
        totalStock: false, // 总存开关,false代表关闭总存，true证明要总存
        actualAmount: '', // 实进量
        actualSell: '', // 实销量
        brandedNameList: this.brandName || [], // 品牌名称数组
        businessList: [], // 业务数组
        commodityNameList: [], // 品名名称数组
        commodityTypeList: [], // 大类（部类编号）数组
        customerNoList: this.searchNo || [], // 客户编号数组 (客户)
        customerRepertory: this.repertoryValue || '', // 客存 >=
        endDate: '', // 结束日期(yyyy-MM-dd HH:mm:ss)
        factoryRepertory: '', // 库存 >=
        headquartersNo: '', // 总店编号
        isExport: false, // 是否导出
        isCustomerTotal: 0, // 客户合计 0未开启1开启
        isHeadquartersTotal: 0, // 总店合计 0未开启1开启
        isRepertoryZero: '', // 累计 <> 0 (库存>0) 0未开启1开启
        kindsNumberList: [], //  货号数组
        limit: this.limit, // 分页条数
        page: this.currentPage, // 当前的页码
        quartIdList:
          JSON.stringify(this.quarterIdList)
            .replace(/\[|]/g, '')
            .replace(/\"|"/g, '') || [], // 季度id数组
        // 如果多选下拉框是一个数组，那么就要转字符串取数组
        quartNameList: [], // 季度名称数组
        selectType: 2, // 查询类型 1：一维表 2：二维表
        softwareCustomerId: '', // 软件客户id
        startDate: '', // 开始日期(yyyy-MM-dd HH:mm:ss)
        styleNumberList: this.kindsNumber || [], //型号(款号)数组，多个款号用 ','分割
        type: 0, // 身份（0客户1厂商）
        warehouseNo: '' // 仓库编号
      }
      // console.log(obj, 'obj')
      // const { data: res } = await getAllInventoryDataApi(obj)
      // console.log(res, ' getAllInventoryDataApi()')
      // return
      let obj1 = {
        remark: this.courier,
        fold: this.customerNo,
        quarterIdList:
          this.quarterIdList == ''
            ? null
            : JSON.stringify(this.quarterIdList)
                .replace(/\[|]/g, '')
                .replace(/\"|"/g, ''),
        brandedName: this.brandName == '' ? null : this.brandName,
        callout: this.callout,
        operator: this.operator,
        startTime:
          this.dateList == null
            ? null
            : this.dateList[0].slice(0, 10) + ' 00:00:00',
        endTime:
          this.dateList == null
            ? null
            : this.dateList[1].slice(0, 10) + ' 23:59:59',
        sequenceStatus:
          this.sequenceStatus == '全部'
            ? ''
            : this.sequenceStatus == ''
            ? ''
            : this.sequenceStatus == '预调'
            ? '预调'
            : '已调',
        'pageData.page': this.currentPage1,
        'pageData.limit': this.limit1
      }
      console.log(obj1)

      //客户二维接口查询  店铺库存查询
      getStoreInventory(obj).then((res) => {
        console.log(res.data, 'res.data')
        if (res.data.code == 200) {
          this.dataLen = res.data.total
          for (let e in res.data.data) {
            if (res.data.data[e].repertoryFiveNumber == 0)
              res.data.data[e].repertoryFiveNumber = ''
            if (res.data.data[e].repertorySevenNumber == 0)
              res.data.data[e].repertorySevenNumber = ''
            if (res.data.data[e].repertoryNineNumber == 0)
              res.data.data[e].repertoryNineNumber = ''
            if (res.data.data[e].repertoryElevenNumber == 0)
              res.data.data[e].repertoryElevenNumber = ''
            if (res.data.data[e].repertoryThirteenNumber == 0)
              res.data.data[e].repertoryThirteenNumber = ''
            if (res.data.data[e].repertoryFifteenNumber == 0)
              res.data.data[e].repertoryFifteenNumber = ''
            if (res.data.data[e].repertorySeventeenNumber == 0)
              res.data.data[e].repertorySeventeenNumber = ''
            if (res.data.data[e].repertoryNineteenNumber == 0)
              res.data.data[e].repertoryNineteenNumber = ''
            if (res.data.data[e].repertoryTwentyOneNumber == 0)
              res.data.data[e].repertoryTwentyOneNumber = ''
            if (res.data.data[e].repertoryTwentyThreeNumber == 0)
              res.data.data[e].repertoryTwentyThreeNumber = ''
            if (res.data.data[e].repertoryFNumber == 0)
              res.data.data[e].repertoryFNumber = ''
            if (res.data.data[e].customerRepertoryNumber == 0)
              res.data.data[e].customerRepertoryNumber = ''
            if (res.data.data[e].customerRepertoryMoney == 0)
              res.data.data[e].customerRepertoryMoney = ''
          }
          console.log(res.data.data) // 这是一个大数组，里面包含着每一项

          // 双重for循环， 去掉所有的0
          for (const item of res.data.data) {
            for (const key in item) {
              if (item[key] === 0) {
                item[key] = ''
              }
            }
          }
          // 去掉0之后，再赋值
          this.tableData2 = res.data.data
        }
        if (res.data.data == null && this.currentPage != 1) {
          //分页到选到大于第一页时查询条件不是第一页 可能数据为null 调整当前页数
          this.limit = 20
          this.currentPage = 1
          this.search()
        }
      })
      //店铺调货查询
      getTransfer(obj1).then((res) => {
        // console.log(res.data, 'obj1')
        if (res.data.code == 200) {
          this.dataLen1 = res.data.total
          this.tableData1 = res.data.data
        }
        if (res.data.data == null && this.currentPage1 != 1) {
          this.limit1 = 20
          this.currentPage1 = 1
          this.search()
        }
      })
    },

    searchNoBlur() {
      for (let i of this.shopList) {
        if (this.searchNo == i.value1) {
          this.searchName = i.value
          this.customerId = i.id
          return
        }
      }
      if (this.searchNo) {
        this.$message.info('编号不存在')
      }
      this.searchName = ''
      this.searchName = ''
      this.customerId = ''
    },
    searchNameChange() {
      for (let i of this.shopList) {
        if (this.searchName == i.value) {
          this.searchNo = i.value1
          this.customerId = i.id
          return
        }
      }
    },
    change1() {
      for (let i of this.shopList) {
        if (this.customerNo == i.value1) {
          this.customerName = i.value
        }
      }
    },
    change2() {
      for (let i of this.shopList) {
        if (this.customerName == i.value) {
          this.customerNo = i.value1
        }
      }
      if (this.customerName == this.calloutName) {
        this.$message({
          type: 'warning',
          message: '调入调出店铺不能一样'
        })
        this.customerName = ''
        this.customerNo = ''
      }
    },
    change3() {
      for (let i of this.shopList) {
        if (this.callout == i.value1) {
          this.calloutName = i.value
        }
      }
    },
    change4() {
      for (let i of this.shopList) {
        if (this.calloutName == i.value) {
          this.callout = i.value1
        }
      }
      if (this.customerName == this.calloutName) {
        this.$message({
          type: 'warning',
          message: '调入调出店铺不能一样'
        })
        this.calloutName = ''
        this.callout = ''
      }
    },
    //指定列求和
    getList(param) {
      // console.log(this.zt)
      const { columns, data } = param
      const sums = []
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '合计'
          return
        }
        const values = data.map((item) => Number(item[column.property]))
        if (
          column.property === 'repertoryFiveNumber' ||
          column.property === 'repertorySevenNumber' || //二维
          column.property === 'repertoryNineNumber' ||
          column.property === 'repertoryElevenNumber' ||
          column.property === 'repertoryThirteenNumber' ||
          column.property === 'repertoryFifteenNumber' ||
          column.property === 'repertoryNineteenNumber' ||
          column.property === 'repertoryTwentyOneNumber' ||
          column.property === 'repertoryTwentyThreeNumber' ||
          column.property === 'repertoryFNumber' ||
          column.property === 'customerRepertoryNumber' ||
          column.property === 'customerRepertoryMoney' ||
          column.property === 'repertorySeventeenNumber'
        ) {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr)
            if (!isNaN(value)) {
              return prev + curr
            } else {
              return prev
            }
          }, 0)
          sums[index]
        }
      })
      return sums
    }
  },
  watch: {
    dataLen(a, b) {
      this.pagesNum = Math.ceil(this.dataLen / this.limit)
      console.log(this.pagesNum)
    },
    limit(a, b) {
      this.pagesNum = Math.ceil(this.dataLen / this.limit)
    },
    dataLen1(a, b) {
      this.pagesNum1 = Math.ceil(this.dataLen1 / this.limit1)
      console.log(this.pagesNum)
    },
    limit1(a, b) {
      this.pagesNum1 = Math.ceil(this.dataLen1 / this.limit1)
    },
    callout(a, b) {
      if (a != undefined) {
        this.callout = a.toUpperCase().trim()
      }
    },
    customerNo(a, b) {
      if (a != undefined) {
        this.customerNo = a.toUpperCase().trim()
      }
    },
    kindsNumber(a, b) {
      if (a != undefined) {
        this.kindsNumber = a.toUpperCase().trim()
      }
    }
  },
  created() {
    let jxQuarterVal = document.cookie.match(RegExp('jxQuarter' + '=([^;]+)'))
    let operatorVal = document.cookie.match(RegExp('jxAgent'+'=([^;]+)'))
    this.jxQuarter = jxQuarterVal ? jxQuarterVal[1] : null
    this.operator = operatorVal ? operatorVal[1] : null
    
    getBarCode().then((res) => {
      console.log(res.data)
      this.manufacturerBarCode = res.data.data[0]
    })
    // 默认选之前一周
    this.dateList = [this.getLastWeek(), this.getNowTime()]

    // 获取品牌
    getBranded().then((res) => {
      // console.log(res)
      res.data.data.forEach((e) => {
        this.brandList.push({ value: e.name, label: e.name })
      })
    })

    //季度
    getQuarter().then((res) => {
      console.log(res.data)
      let qList = res.data.data
      qList.forEach((e) => {
        this.quarterList1.push({ label: e.name, value: e.id })
      })
      console.log(this.quarterList1, '季度')
    })
    //客户 -> 店铺
    getClient().then((res) => {
      console.log(res.data)
      let list = res.data.data
      list.forEach((e) => {
        if (e.stop != 1) {
          this.shopList.push({
            value: e.name,
            label: e.name,
            value1: e.no,
            id: e.id
          })
        }
        if (e.name == this.operator) {
          // this.customerId = e.id
          // this.searchNo = e.no
          // this.searchName = e.name
        }
      })
    })
  }
}
</script>
<style scoped>
.storeInventory {
  margin-right: 15px;
  padding: 0 15px;
  background-color: white;
  height: 93.5vh;
  position: relative;
}
.cog-top {
  padding: 15px 0;
  border-bottom: 2px solid #f4f4f4;
  white-space: nowrap;
}
.cog-top p:first-child {
  line-height: 30px;
  display: inline-block;
  margin-right: 10px;
}
.cog-top p:not(:first-child) {
  line-height: 30px;
  width: 75px;
  text-align: right;
  display: inline-block;
  margin-right: 8px;
}
.cog-btn {
  display: flex;
  justify-content: space-between;
  padding: 15px 0;
}
.footView span {
  float: left;
  margin-right: 48px;
  line-height: 6vh;
  font-size: 14px;
}
.footView span i {
  margin-right: 5px;
}
.cog-tab {
  display: flex;
  width: 100%;
  height: 74%;
}
.cog-tab p {
  display: inline-block;
}
.expt {
  width: 260px;
  height: 170px;
  position: absolute;
  top: 20%;
  box-shadow: 0 3px 3px 3px #f4f4f4;
  left: 16%;
  z-index: 2;
  background: white;
  font-weight: 700;
  padding: 15px;
}
.expt > div {
  margin-top: 10px;
  text-align: end;
}
.riqi {
  margin-top: 15px;
}

#content2 {
  width: 30%;
}
#content1 {
  width: 69%;
}

.divider {
  width: 1%;
  height: 88%;
  background-color: #f4f4f4;
  cursor: pointer;
  margin-top: 2%;
}
.divider i {
  position: absolute;
  top: 50%;
  font-weight: 1000;
  color: #017aff;
}
</style>

<style>
.storeInventory .el-input {
  height: 30px;
  width: 160px;
}
.storeInventory .el-input__inner {
  height: 30px;
}
.storeInventory .el-checkbox.is-bordered {
  padding: 5px 10px 0 10px;
  height: 30px;
}
.storeInventory .cog-top .el-date-editor .el-range__icon {
  line-height: 23px;
}
.storeInventory .cog-top .el-date-editor .el-range-separator {
  line-height: 23px;
  width: 8%;
}
.storeInventory .cog-top .riqi .el-date-editor.el-input__inner {
  width: 473px;
}
.storeInventory .el-input__icon {
  line-height: 30px;
}
.storeInventory .el-pagination {
  text-align: end;
}
.storeInventory .el-pagination--small .el-pagination__editor,
.el-pagination--small .el-pagination__editor.el-input .el-input__inner {
  width: 50px;
  height: 30px;
  margin-right: 5px;
}
.storeInventory .el-pagination.is-background.el-pagination--small .btn-next,
.el-pagination.is-background.el-pagination--small .btn-prev,
.el-pagination.is-background.el-pagination--small .el-pager li {
  width: 30px;
  height: 30px;
}
.storeInventory .el-pagination--small button,
.el-pagination--small span:not([class*='suffix']) {
  margin-right: 10px;
}
.storeInventory .el-pagination .el-select .el-input .el-input__inner {
  width: 120px;
}
</style>
